<%@ page language="java"
         import="com.ruohi.gift.order.OrderOperate,com.ruohi.gift.order.OrderStatus,com.ruohi.manage.DBType,com.ruohi.manage.PoolManager,com.ruohi.manage.Tools,com.ruohi.util.common.CommonDate"
         pageEncoding="UTF-8" %>
<%@ page import="com.ruohi.util.common.CommonString" %>
<%@ page import="com.ruohi.util.common.Env" %>
<%@ page import="com.ruohi.util.dbutil.DBHelper" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%
	Connection connection = null;
	String tablePrefix = Env.getInstance().getProperty("table_prefix");
	DBHelper dbHelper = DBHelper.getInstance();
	Map model = new HashMap();
	String tableName = " gift_order ";
	try{
		Map enumMap=(Map)application.getAttribute("enumMap");
		
		connection = PoolManager.getConnection(DBType.getDBTypeByEnum("106013"));
		String id = CommonString.getFormatPara(request.getParameter("id"));
		String channelUUID = CommonString.getFormatPara(request.getParameter("channel_uuid"));
		if(null!=id&&!"".equals(id)){
			model = dbHelper.getMap(" select *,(select back_enable_operate from gift_order_status_operate where order_status=gift_order.order_status) as statusoperate from "+tableName+" where uuid = ? ",new Object [] {id} , connection);
		}
		if("".equals(channelUUID)&&null!=model){
			channelUUID = (String)model.get("channel_uuid");
		}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=Env.getInstance().getProperty("project_name") %></title>
<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="/plugin/editor/ueditor/editor_config.js"></script>
<script type="text/javascript" charset="utf-8" src="/plugin/editor/ueditor/editor_all_min.js"></script>
<script type="text/javascript" src="/plugin/area/city/citys.js"></script>
<link rel="stylesheet" type="text/css" href="/plugin/editor/ueditor/themes/default/ueditor.css"/>
<style type="text/css">
	body { *height:auto; }
	.formRight { width:150px; text-align:left; }
</style>
</head>

<body style="margin: 0;padding: 0; overflow-x: hidden; overflow-y: auto; ">
<form name="theform" id="theform" action="/backend/action/crud.jsp?enumNo=106013">
  <div class="formDiv">
  	<div class="group">
					<span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span>
					<span class="groupTitle">订单信息</span>
				</div>
				<div class="formLeft" style="text-align: right">订单编号：</div>
				<div class="formRight" style="text-align: left">
					<label><%=CommonString.getFormatPara(model.get("order_num")) %></label>
				</div>
				<div class="formLeft" style="text-align: right">下单时间：</div>
				<div class="formRight" style="text-align: left">
					<label><%=CommonDate.getFormatDate("yyyy-MM-dd HH:mm", model.get("add_date"))%></label>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">状态：</div>
				<div class="formRight" style="width: 300px;text-align: left">
					<label>
					<%
						String smsTip = "";
						if(CommonString.getFormatInt(model.get("order_status")).equals(OrderStatus.SHIPPED)){
							if(CommonString.getFormatInt(model.get("sms_alert_send")) == 1){
								smsTip = "(已发送短信提醒)";
							}else if(CommonString.getFormatInt(model.get("sms_alert_send")) == 0){
								smsTip = "(未发送短信提醒)";
							}else{
								smsTip = "(短信提醒发送失败)";
							}
						}
					%>
					<%=OrderStatus.showStatus(Integer.valueOf(CommonString.getFormatPara(model.get("order_status")))) + smsTip %>
					&nbsp;&nbsp;&nbsp;&nbsp;<%=OrderOperate.showOrderEnableOperate(CommonString.getFormatPara(model.get("order_num")),CommonString.getFormatPara(model.get("statusoperate")),"Back") %>
					<%
						if(CommonString.getFormatInt(model.get("order_status")) == OrderStatus.REFUND){
							Map refundMap = dbHelper.getMap("select refund_price from gift_product_repair where order_num='" + CommonString.getFormatPara(model.get("order_num")) + "'", connection);
							if(refundMap != null){
					%>
					退款金额：<%=CommonString.getFormatDouble(refundMap.get("refund_price")) %>
					<%
							}
						}
					%>
					</label>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">商品金额：</div>
				<div class="formRight" style="text-align: left">
					<input type="text" class="jr_text" id="zd_product_total_price" name="zd_product_total_price" value="<%=CommonString.getFormatDouble(model.get("product_total_price")) %>" />
				</div>	
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">运费：</div>
				<div class="formRight" style="text-align: left">
					<input type="text" class="jr_text" id="zd_ship_total_price" name="zd_ship_total_price" value="<%=CommonString.getFormatDouble(model.get("ship_total_price")) %>" />
				</div>	
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">备注：</div>
				<div class="formRight" style="text-align: left">
					<label><%=CommonString.getFormatPara(model.get("remark")) %></label>
				</div> 
                <div style="clear:left;">
                <div class="formLeft" style="text-align: right">线下付款备注：</div>
				<div class="formRight" style="text-align: left; width:300px;">
					<input type="text" class="jr_text" id="zd_offline_pay_remark" name="zd_offline_pay_remark" value="<%=CommonString.getFormatPara(model.get("offline_pay_remark")) %>" />
				</div> 
                <div style="clear:left;">
                <div class="formLeft" style="text-align: right">发货备注：</div>
				<div class="formRight" style="text-align: left; width:300px;">
					<input type="text" class="jr_text" id="zd_ship_remark" name="zd_ship_remark" value="<%=CommonString.getFormatPara(model.get("ship_remark")) %>" />
				</div> 
                <div style="clear:left;">
                </div><div class="group">
					<span><img
							src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" />
					</span>
					<span class="groupTitle">物流公司及单号</span>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right;">物流公司代码：</div>
				<div class="formRight" style="width:400px;">
					<input type="text" class="jr_text" style="width:150px;" id="zd_ship_company" name="zd_ship_company" value="<%=CommonString.getFormatPara(model.get("ship_company")) %>" />
					<a href="http://zt.01ny.cn/tg/WebPage/help.htm" target="_blank">查看物流公司代码</a>
				</div> 
                <div style="clear:left;">
                <div class="formLeft" style="text-align: right">单号：</div>
				<div class="formRight" style="text-align: left; width:200px;">
					<input type="text" class="jr_text" id="zd_ship_company_no" name="zd_ship_company_no" value="<%=CommonString.getFormatPara(model.get("ship_company_no")) %>" />
					<a href="/backend/gift.21-sun.com/gift_order/kuaidi.jsp?com=<%=CommonString.getFormatPara(model.get("ship_company"))%>&no=<%=CommonString.getFormatPara(model.get("ship_company_no"))%>" target="_blank">查看物流信息</a>
				</div> 
                <div style="clear:left;">
                </div><div class="group">
					<span><img
							src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" />
					</span>
					<span class="groupTitle">商品信息</span>
				</div>
				<div style="clear:left;"></div>
				
				<div id="maingrid" style=" margin-left: 19px; padding: 0;"></div>
					<%
						String fields = "uuid,product_no,buy_price,buy_amount,key_param_value,(select name from gift_product where gift_product.no=gift_order_product.product_no) as product_name,(select price_promotion from gift_product where gift_product.no=gift_order_product.product_no) as price_promotion,(SELECT name FROM gift_supplier WHERE gift_supplier. no = (SELECT supplier FROM gift_product WHERE gift_product. NO = gift_order_product.product_no ) ) AS supplier_name";
					String whereStr = " and order_num='" +CommonString.getFormatPara(model.get("order_num"))+ "'";
					String orderByStr = " id desc";
				%>
				<script type="text/javascript">
					var grid;
					var tableName = 'gift_order_product';
					var fields = '<%=fields %>';
					var whereStr = "<%=whereStr %>";
					var orderBy = '<%=orderByStr %>';
					var columnsArr = [];
					var url = '';
					var conditionStr = '';
					var main = '';
					var params = [];
					params.push({'name':'enumNo','value':'106013'});
				jQuery(function() {
					jQuery.ligerDefaults.Grid.formatters['date'] = function(content,
							column) {
						return content.substring(0, content.indexOf(' '));
					}
					jQuery.ligerDefaults.Grid.formatters['is'] = function(content,
							column) {
						if (content == 1) {
							return '是';
						}
						return '否';
					}
					jQuery.ligerDefaults.Grid.formatters['sex'] = function(content,
							column) {
						if (content == 1) {
							return '男';
						}
						return '女';
					}
					url = "/backend/action/liger.jsp";
					params.push({'name':'tableName','value':tableName});
					params.push({'name':'fields','value':fields});
					params.push({'name':'whereStr','value':whereStr});
					params.push({'name':'orderBy','value':orderBy});
					grid = jQuery("#maingrid").ligerGrid({
								columns : columnsArr,
								url : url,
								width : '95%',
								checkbox : false,
								selectRowButtonOnly : true,
								parms : params,
								rownumbers : true,
								enabledEdit: true,
								clickToEdit:true,
								onAfterEdit: f_onAfterEdit,
								usePager: false
							});
					jQuery("#pageloading").hide();
				});
				jQuery(".searchForm input[type=text]").keypress(function(e){
					if(e.keyCode==13){
						doSearch();
					}
				});
				//列数组
				columnsArr =  [ 
					{ display : '商品编号', name : 'product_no', align : 'center' , type : 'string' , width : 130 } ,
					{ display : '商品名称', name : 'product_name', align : 'left' , type : 'string' , width : 260,render : function(row){
						var name = row.product_name;
						if(row.key_param_value!=""){
							var keyParaValueAry = row.key_param_value.split(",");
							if(keyParaValueAry!=null && keyParaValueAry.length>0){
								for(var i=0; i<keyParaValueAry.length; i++){
									name += "  " + getEnum(keyParaValueAry[i], "enumMap");
								}
							}
						}
                        return "<a class='link' href='http://www.52sdskj.com/goods/" + row.product_no + ".htm' target='_blank'>" + name + "</a>";
					} } ,
                    {display: '供应商', name: 'supplier_name', align: 'center', type: 'string', width: 105},
                    {
                        display: '购买价',
                        name: 'buy_price',
                        align: 'center',
                        type: 'string',
                        width: 80,
                        editor: {type: 'float'},
                        render: function (row) {
						return row.buy_price.toFixed(2);
                        }
                    },
                    {display: '购买数量', name: 'buy_amount', align: 'center', type: 'string', width: 60},
                    {
                        display: '小计', align: 'center', type: 'string', width: 80, render: function (row) {
						return (row.buy_price*row.buy_amount).toFixed(2);
					}} 
				];	
				
				//编辑后事件 
		        function f_onAfterEdit(e){
		            if (e.column.name == "buy_price"){
		                var buy_price = e.value;
		                var uuid = e.record.uuid;
		                $.ajax({
		                	type:"post",
		                	url:"/backend/action/ajax_r.jsp",
		                	data:{flag:"updateBuyPrice", uuid:uuid, buy_price:buy_price, enumNo:"106013"},
		                	success:function(result){
		                		if($.trim(result)=="1"){
		                			jrSuccess("更新购买价成功");
		                		}
		                	}
		                });
		            }
		        }
			</script>
		</div>
		<div style="text-align: right; margin-right: 50px; font-size: 10pt; font-weight: bold;color: red;">商品金额：<%=Tools.getFormatDecimal(CommonString.getFormatDouble(model.get("product_total_price")), 2) %></div>
		<div style="text-align: right; margin-right: 50px; font-size: 10pt; font-weight: bold;color: red;">-积分抵现：<%=Tools.getFormatDecimal(CommonString.getFormatDouble(model.get("point_total_price")), 2) %></div>
		<div style="text-align: right; margin-right: 50px; font-size: 10pt; font-weight: bold;color: red;">-优惠券抵现：<%=Tools.getFormatDecimal(CommonString.getFormatDouble(model.get("coupon_total_price")), 2) %></div>
		<div style="text-align: right; margin-right: 50px; font-size: 10pt; font-weight: bold;color: red;">+运费：<%=Tools.getFormatDecimal(CommonString.getFormatDouble(model.get("ship_total_price")), 2) %></div>
		<div style="text-align: right; margin-right: 50px; font-size: 10pt; font-weight: bold;color: red;">-商品卡支付金额：<%=Tools.getFormatDecimal(CommonString.getFormatDouble(model.get("card_total_price")), 2) %></div>
		<%
			double total = CommonString.getFormatDouble(model.get("product_total_price")) - CommonString.getFormatDouble(model.get("point_total_price")) - CommonString.getFormatDouble(model.get("coupon_total_price"));
			if(total < 0){
				total = 0;
			}
			total += CommonString.getFormatDouble(model.get("ship_total_price"));
			total -= CommonString.getFormatDouble(model.get("card_total_price"));
			if(total < 0){
				total = 0;
			}
		%>
		<div style="text-align: right; margin-right: 50px; font-size: 15pt; font-weight: bold;color: red;">应付金额：<%=Tools.getFormatDecimal(total, 2) %></div>
		<div style="clear: left;"></div>
                
                <div class="group">
					<span><img
							src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" />
					</span>
					<span class="groupTitle">收件人信息</span>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft machine_left" style="text-align: right">
					收件人：
				</div>
				<div class="formRight" style="text-align: left">
					<label  name="zd_receive_name" id="zd_receive_name" ><%=CommonString.getFormatPara(model.get("receive_name")) %></label>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">收件人联系方式：</div>
				<div class="formRight" style="text-align: left">
					<label  name="zd_receive_phone" id="zd_receive_phone" ><%=CommonString.getFormatPara(model.get("receive_phone")) %></label>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">送货省份：</div>
				<div class="formRight" style="text-align: left">
					<label  name="zd_receive_province" id="zd_receive_province" ><%=CommonString.getFormatPara(model.get("receive_province")) %></label>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">送货城市：</div>
				<div class="formRight" style="text-align: left">
					<label  name="zd_receive_city" id="zd_receive_city" ><%=CommonString.getFormatPara(model.get("receive_city")) %></label>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">送货地址：</div>
				<div class="formRight" style="text-align: left; width:500px;">
					<label  name="zd_receive_address" id="zd_receive_address" ><%=CommonString.getFormatPara(model.get("receive_address")) %></label>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">收件人邮编：</div>
				<div class="formRight" style="text-align: left">
					<label  name="zd_receive_zip" id="zd_receive_zip" ><%=CommonString.getFormatPara(model.get("receive_zip")) %></label>
				</div>
				<div style="clear:left;"></div>
				<div class="group">
					<span><img
							src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" />
					</span>
					<span class="groupTitle">发票信息</span>
				</div>
					<%--<div style="clear:left;"></div>--%>
					<%--<div class="formLeft" style="text-align: right">发票类型：</div>--%>
					<%--<div class="formRight" style="text-align: left">--%>
					<%--<label><%=CommonString.getFormatPara(enumMap.get(model.get("invoice_type"))) %></label>--%>
					<%--</div>--%>
				<div style="clear:left;"></div>
				<div class="formLeft" style="text-align: right">发票抬头：</div>
				<div class="formRight" style="text-align: left">
					<% 
						if(CommonString.getFormatPara(model.get("invoice_title_type")).equals("145001")){
					%>
					<label><%=CommonString.getFormatPara(enumMap.get(model.get("invoice_title_type"))) %></label>
					<%}else{ %>
					<label><%=CommonString.getFormatPara(model.get("invoice_title")) %></label>					
					<%} %>
				</div>
				<div style="clear:left;"></div>
					<div class="formLeft" style="text-align: right">发票税号：</div>
				<div class="formRight" style="text-align: left">
					<label><%=CommonString.getFormatPara(model.get("invoice_num")) %>
					</label>
				</div>
					<%--<div class="formLeft" style="text-align: right">发票内容：</div>--%>
					<%--<div class="formRight" style="text-align: left">--%>
					<%--<label><%=CommonString.getFormatPara(enumMap.get(model.get("invoice_content"))) %></label>--%>
					<%--</div>--%>
					<%--<div style="clear:left;"></div>--%>
		<input type="hidden" name="tableName" id="tableName" value="gift_order" />
		<input type="hidden" name="zd_id" id="zd_id" value="<%=CommonString.getFormatPara(model.get("id")) %>" />
</form>
</body>
</html>
<script type="text/javascript" src="/plugin/jquery/jquery.form.js"></script>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/plugin/date/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" prefix="<%=tablePrefix %>" type="text/javascript"></script>
<script src="/plugin/validator/wofoshan/validator.min.js" type="text/javascript"></script>
<script src="/backend/scripts/gift_order_operate.js" type="text/javascript"></script>
<script type="text/javascript">
	function doSub(dialog){
		var rs = Validator.Validate(document.getElementById("theform"),1);
		if(rs){
			jQuery("#theform").ajaxSubmit({
				type : "POST",
				async : false ,
				success : function(data) {
					var rs = parseInt(jQuery.trim(data), 10);
					if (rs > 0 ) {
						dialog.close();
						return true;
					}else{
						jrError("保存失败！");
					}
				}
			});
		}
	}
</script>
<%
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		DBHelper.freeConnection(connection);
	}
%>